home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C++ Templates / mmCommon.c < prev    next >
Text File  |  1995-02-06  |  71KB  |  2,218 lines

  1. $$Message MM Common, mm:mmCommon$Prototype.name$.cp
  2. $$File mm:mmCommon$Prototype.name$.cp
  3. /*  mmCommon$Prototype.name$                         Common */
  4. /*  $CopyRight$ */
  5.  
  6. /*
  7.     Name:  mmCommon$Prototype.name$.c
  8.     Function:  Common for the Marksman¬ specific code.
  9.     History: $Date$ Original by $Author$
  10.     02/12/94 IT Makers, Made TypeList in Open file, and Reply record in Select
  11.         Volume to be local variables instead of in a floating object.
  12. */
  13.  
  14.  
  15. #include "mmCommon$Prototype.name$.h"            /* Common */
  16. #include "Common$Prototype.name$.h"                /* Common */
  17.  
  18. /* ======================================================= */
  19.  
  20. CApplication    *gApplication;                    /* The application itself */
  21. CMenus            *gMenus;                        /* Menu handler */
  22. CPreferences    *gPreferences;                    /* Preferences handler */
  23. CFiles            *gFiles;                        /* Files handler */
  24. CPrinting        *gPrinting;                        /* Printing handler */
  25.  
  26. UserEventHRec    UserEventList;                    /* User Event record list start */
  27. EventRecord        myEvent;                        /* Event record for all events */
  28. Boolean            WNE;                            /* WaitNextEvent trap is available */
  29. short            SleepValue;                        /* Sleep value for Wait on events */
  30. Boolean            doneFlag;                        /* Exit program flag */
  31. TEHandle        theInput;                        /* Used in text edit selections */
  32. RgnHandle        cursorRgn;                        /* Cursor region for WaitNextEvent */
  33. short            ReplyMode;                        /* Reply mode for AppleEvents */
  34.  
  35. Rect            tempRect;                        /* Temporary rect, not for long term use */
  36. Str255            sTemp;                            /* Temporary string, not for long term use */
  37. short            tempChar;                        /* Temporary use character */
  38. long            LTemp;                            /* Temporary use long variable */
  39. short            DType;                            /* Temporary use Type of dialog item */
  40. Handle            DItem;                            /* Temporary use Handle to the dialog item */
  41. ControlHandle    CItem;                            /* Temporary use Control handle */
  42.  
  43. WindowLocRec    theWindowLocRec;
  44.  
  45. Boolean            Doing_MovableModal;                /* For Movable Modal dialogs */
  46. Boolean            HoldOffUserEvents;                /* Flag for holding off UserEvents */
  47. Boolean            InTheForeground;                /* Flag for running in MultiFinder foreground */
  48.  
  49. HasRec            Has;                            /* Gestalt check results */
  50.  
  51. RGBColor        Black_ForeColor,White_BackColor;/* Standard colors */
  52. RGBColor            DrawingColor;                /* Temp drawing color, short life span use only */
  53.  
  54. $$Loop Menus
  55. MenuHandle    Menu_$Menu.name$;                    /* Menu handle, $Menu.FullName$ */
  56. $$EndLoop
  57.  
  58. $$Loop HierMenus
  59. MenuHandle    Menu_$Menu.name$;                    /* Hier Menu handle, $Menu.FullName$ */
  60. $$EndLoop
  61.  
  62. CmmAlert                *gCurrentAlert;            /* The current Alert object */
  63. $$Loop Alerts
  64. CA$Worksheet.name$        *g$Worksheet.name$;        /* The Alert object */
  65. $$EndLoop Alerts
  66. CmmModalDialog            *gCurrentModalDialog;    /* The current Modal Dialog object */
  67. $$Loop ModalDialogs
  68. CD$Worksheet.name$        *g$Worksheet.name$;        /* The Modal Dialog object */
  69. $$EndLoop
  70. $$Loop ModelessDialogs
  71. CMD$Worksheet.name$        *g$Worksheet.name$;        /* The Modeless Dialog object */
  72. $$EndLoop
  73. $$Loop Windows
  74. CW$Worksheet.name$        *g$Worksheet.name$;        /* The Window object */
  75. $$EndLoop
  76.  
  77.  
  78. #define            LowestWindowIndex            0
  79. #define            HighestWindowIndex            10
  80. WindowPtr        TopMostWindows[12];
  81. WindowPtr        BottomMostWindows[12];
  82.  
  83. #define            lmWindowList                0x000009D6
  84.  
  85. /* Variables used by Select Volume */
  86. short            Last_vRefNum;
  87. long            Last_parID;
  88. Str255            Last_Name;
  89.  
  90. ProcessSerialNumber    gSelfPSN;
  91. AEAddressDesc                gSelfAddress;
  92.  
  93.  
  94. static void    VerifyWindowLayers(void);
  95.  
  96. static pascal Boolean mySelectCustomFileFilter(CInfoPBPtr pb,Ptr myDataPtr);
  97.  
  98. static pascal short mySelectDlgFilter(short item,DialogPtr theDialog,Ptr myDataPtr);
  99.  
  100. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  101.     ControlHandle *theCItem);
  102.  
  103. /* ======================================================= */
  104. /* ======================================================= */
  105.  
  106. /* Routine: VerifyWindowLayers */
  107. /* Purpose: Verify all windows are at the proper layer */
  108.  
  109. static void VerifyWindowLayers()
  110. {
  111. short        Index,theLayer;
  112. WindowPeek    theWindowPeek;
  113. long         *theWindowListPtr,theRefCon;
  114. WindowPtr    theWindowPtr,theOutOfOrderWindowPtr;
  115. Boolean        Out_Of_Place;
  116.  
  117.  
  118. Out_Of_Place = true;
  119. while (Out_Of_Place)
  120.     {
  121.     Mk_ClearLayers();                                /* Clear all arrays, we will refill them */
  122.     theOutOfOrderWindowPtr = nil;
  123.     Out_Of_Place = false;
  124.  
  125.     Index = HighestWindowIndex + 1;
  126.     theWindowListPtr = (long *)lmWindowList;        /* Get the window list start */
  127.     theWindowPeek = (WindowPeek)*theWindowListPtr;    /* Get the window list start */
  128.     while ((theWindowPeek != nil) && (!Out_Of_Place))
  129.         {
  130.         if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  131.             {
  132.             theWindowPtr = (WindowPtr)theWindowPeek;/* Get the window pointer */
  133.  
  134.             theRefCon = GetWRefCon(theWindowPtr);
  135.             theRefCon = theRefCon & 0xFF000000;        /* Mask off, to get the layer */
  136.             theLayer = theRefCon >> 24;                /* Move into lower byte */
  137.             if (theLayer < LowestWindowIndex)        /* Pin at 0 */
  138.                 theLayer = LowestWindowIndex;
  139.             if (theLayer > HighestWindowIndex)        /* Pin at top */
  140.                 theLayer = HighestWindowIndex;
  141.             if (theLayer > Index)
  142.                 {
  143.                 Index = theLayer;
  144.                 Out_Of_Place = true;
  145.                 if (theOutOfOrderWindowPtr != nil)
  146.                     SendBehind(theOutOfOrderWindowPtr,theWindowPtr);
  147.                 }
  148.             else if (theLayer < Index)
  149.                 {
  150.                 Index = theLayer;
  151.                 TopMostWindows[theLayer] = theWindowPtr;
  152.                 BottomMostWindows[theLayer]  = theWindowPtr;
  153.                 }
  154.             else
  155.                 BottomMostWindows[theLayer]  = theWindowPtr;
  156.             theOutOfOrderWindowPtr = theWindowPtr;
  157.             }
  158.         theWindowPeek = theWindowPeek->nextWindow;/* Get the next window */
  159.         }
  160.     }
  161.  
  162. }
  163.  
  164. /* ======================================================= */
  165.  
  166. /* Routine: Mk_BehindWindow */
  167. /* Purpose: Get which window to place us behind */
  168.  
  169. WindowPtr Mk_BehindWindow(short theLayer)
  170. {
  171. short        LayerIndex;
  172. WindowPtr    ReturnWindowPtr;
  173.  
  174.  
  175. ReturnWindowPtr = (WindowPtr)-1;                    /* Default to In front of everyone */
  176.  
  177. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  178.  
  179. LayerIndex = HighestWindowIndex;
  180. while ((LayerIndex > theLayer) && (LayerIndex >= LowestWindowIndex))
  181.     {
  182.     if (BottomMostWindows[LayerIndex] != nil)
  183.         ReturnWindowPtr = BottomMostWindows[LayerIndex];
  184.     LayerIndex = LayerIndex - 1;
  185.     }
  186.  
  187. return(ReturnWindowPtr);
  188. }
  189.  
  190. /* ======================================================= */
  191.  
  192. /* Routine: Mk_RegisterWindow */
  193. /* Purpose: Place layer in RefCon and verify layers */
  194.  
  195. void Mk_RegisterWindow(WindowPtr theWindowPtr,short theLayer)
  196. {
  197. long    theRefCon;
  198. long    theLLayer;
  199.  
  200.  
  201. theRefCon = GetWRefCon(theWindowPtr);                /* Get the window refcon */
  202. theRefCon = theRefCon & 0x00FFFFFF;                    /* Mask off, in case something else is there */
  203. theLLayer = theLayer;                                /* Get the window layer */
  204. theLLayer = theLLayer << 24;                        /* Move into upper byte */
  205. theRefCon = theRefCon | theLLayer;                    /* Mask layer into refcon */
  206. SetWRefCon(theWindowPtr, theRefCon);                /* Set the new refcon */
  207.  
  208. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  209. }
  210.  
  211. /* ======================================================= */
  212.  
  213. /* Routine: Mk_ClearLayers */
  214. /* Purpose: Init our arrays for layered windows */
  215.  
  216. void Mk_ClearLayers()
  217. {
  218. short    Index;
  219.  
  220.  
  221. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  222.     {
  223.     TopMostWindows[Index] = nil;
  224.     BottomMostWindows[Index] = nil;
  225.     }
  226. }
  227.  
  228. /* ======================================================= */
  229.  
  230. /* Routine: Mk_HiliteWindow */
  231. /* Purpose: Hilite our layered window */
  232.  
  233. void Mk_HiliteWindow(WindowPtr theWindowPtr)
  234. {
  235. WindowPeek    theWindowPeek;
  236. long         *theWindowListPtr;
  237. WindowPtr    WasHilighted,CkHilighted,BehindWindow;
  238. long        theRefCon;
  239. short        theLayer,theWasLayer;
  240.  
  241.  
  242. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  243.  
  244. theRefCon = GetWRefCon(theWindowPtr);
  245. theRefCon = 0xFF000000 & theRefCon;                    /* Mask for top byte */
  246. theLayer = theRefCon >> 24;                            /* Move into lower byte */
  247. if (theLayer < LowestWindowIndex)                    /* Pin at 0 */
  248.     theLayer = LowestWindowIndex;
  249. if (theLayer > HighestWindowIndex)                    /* Pin at top */
  250.     theLayer = HighestWindowIndex;
  251.  
  252. theWindowListPtr = (long *)lmWindowList;            /* Get the window list start */
  253. theWindowPeek = (WindowPeek)*theWindowListPtr;        /* Get the window list start */
  254. WasHilighted = nil;
  255. while (theWindowPeek != nil)
  256.     {
  257.     if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  258.         {
  259.         if (theWindowPeek->hilited)
  260.             {
  261.             CkHilighted = (WindowPtr)theWindowPeek;
  262.             theRefCon = GetWRefCon(CkHilighted);
  263.             theRefCon = 0xFF000000 & theRefCon;        /* Mask for top byte */
  264.             theWasLayer = theRefCon >> 24;            /* Move into lower byte */
  265.             if (theWasLayer == theLayer)
  266.                 WasHilighted = CkHilighted;
  267.             }
  268.         }
  269.     theWindowPeek = theWindowPeek->nextWindow;
  270.     }
  271.  
  272. if (theWindowPtr != WasHilighted)
  273.     {
  274.     if (WasHilighted != nil)
  275.         {
  276.         theRefCon = GetWRefCon(WasHilighted);
  277.         theRefCon = 0xFF000000 & theRefCon;            /* Mask for top byte */
  278.         theWasLayer = theRefCon >> 24;                /* Move into lower byte */
  279.         if (theWasLayer < LowestWindowIndex)        /* Pin at 0 */
  280.             theWasLayer = LowestWindowIndex;
  281.         if (theWasLayer > HighestWindowIndex)        /* Pin at top */
  282.             theWasLayer = HighestWindowIndex;
  283.         if (theWasLayer == theLayer)
  284.             {
  285.             HiliteWindow(WasHilighted, false);
  286.             myEvent.message = (long)WasHilighted;
  287.             myEvent.modifiers = 0;
  288.             gApplication->DoActivate(&myEvent);        /* Deactivate, do links */
  289.             }
  290.         }
  291.  
  292.     HiliteWindow(theWindowPtr, true);
  293.     myEvent.message = (long)theWindowPtr;
  294.     myEvent.modifiers = 1;
  295.     gApplication->DoActivate(&myEvent);                /* Activate, do links */
  296.  
  297.     BehindWindow = Mk_BehindWindow(theLayer);        /* Move to correct layer on the screen */
  298.     if ((long)BehindWindow == -1L)
  299.         BringToFront(theWindowPtr);
  300.     else
  301.         SendBehind(theWindowPtr, BehindWindow);
  302.  
  303.     TopMostWindows[theLayer] = theWindowPtr;
  304.     }
  305.  
  306. }
  307.  
  308. /* ======================================================= */
  309.  
  310. /* Routine: Mk_DragWindow */
  311. /* Purpose: Drag our layered window */
  312.  
  313. void Mk_DragWindow(WindowPtr theWindowPtr,Point where, Rect bounds)
  314. {
  315. GrafPtr            savePort;
  316. CGrafPtr        WMgrPort;
  317. RgnHandle        hRegion,dragRgn;
  318. WindowPeek        theWindowPeek;
  319. long            result;
  320. short            Horz,Vert;
  321. CWindowPtr        theCWindowPtr;
  322. Rect            portBounds;
  323. PixMapHandle    thePixMapHandle;
  324.  
  325.  
  326. if (WaitMouseUp())
  327.     {
  328.     theWindowPeek = (WindowPeek)theWindowPtr;
  329.     theCWindowPtr = (CWindowPtr)theWindowPtr;
  330.  
  331.     GetPort(&savePort);
  332.     if (Has.ColorQD)
  333.         GetCWMgrPort(&WMgrPort);
  334.     else
  335.         GetWMgrPort((GrafPtr *)&WMgrPort);
  336.     SetPort((GrafPtr)WMgrPort);
  337.     hRegion = GetGrayRgn();
  338.     SetClip(hRegion);
  339.  
  340.     #if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
  341.     ClipAbove(theWindowPeek);
  342. #else
  343.     ClipAbove((WindowRef)theWindowPeek);
  344. #endif
  345.  
  346.     dragRgn = NewRgn();
  347.     CopyRgn(theWindowPeek->strucRgn, dragRgn);
  348.  
  349.     result = DragGrayRgn(dragRgn, where, &bounds, &bounds, 0, nil);
  350.     Horz = (result & 0x0000FFFF);
  351.     Vert = (result >> 16) & 0x0000FFFF;
  352.  
  353.     if ((Vert != 0x8000) && (Horz != 0x8000))
  354.         {
  355.         if ((theCWindowPtr->portVersion & 0xC000) != 0)
  356.             {
  357.             thePixMapHandle = theCWindowPtr->portPixMap;
  358.             portBounds = (*thePixMapHandle)->bounds;
  359.             }
  360.         else
  361.             portBounds = theWindowPtr->portBits.bounds;
  362.  
  363.         Horz = Horz + (theWindowPtr->portRect.left - portBounds.left);
  364.         Vert = Vert + (theWindowPtr->portRect.top - portBounds.top);
  365.  
  366.         MoveWindow(theWindowPtr, Horz, Vert, false);
  367.         }
  368.  
  369.     DisposeRgn(dragRgn);
  370.     SetPort(savePort);
  371.     }
  372.  
  373. }
  374.  
  375. /* ======================================================= */
  376.  
  377. /* Routine: Mk_Is_FrontWindow */
  378. /* Purpose: Get the front window */
  379.  
  380. Boolean Mk_Is_FrontWindow(WindowPtr theWindowPtr)
  381. {
  382. Boolean    IsFront;
  383. short    Index;
  384.  
  385.  
  386. IsFront = false;
  387. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  388.     {
  389.     if (TopMostWindows[Index] == theWindowPtr)
  390.         IsFront = true;
  391.     }
  392.  
  393. return(IsFront);
  394. }
  395.  
  396. /* ======================================================= */
  397.  
  398. /* Routine: Mk_CloseLayeredWindow */
  399. /* Purpose: Close a layered window */
  400.  
  401. void Mk_CloseLayeredWindow(WindowPtr theWindowPtr)
  402. {
  403. short    Index;
  404.  
  405.  
  406. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  407.     {
  408.     if (TopMostWindows[Index] == theWindowPtr)
  409.         TopMostWindows[Index] = nil;
  410.     if (BottomMostWindows[Index] == theWindowPtr)
  411.         BottomMostWindows[Index] = nil;
  412.     }
  413. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  414. }
  415.  
  416. /* ======================================================= */
  417.  
  418. /* Routine: Init */
  419. /* Purpose: Set the default preferences */
  420.  
  421. void CmmPreferences::Init(void)
  422. {
  423. }
  424.  
  425. /* ======================================================= */
  426.  
  427. /* Routine: GetPrefParams */
  428. /* Purpose: Get the preferences Parameters */
  429.  
  430. void CmmPreferences::GetPrefParams(OSType *PrefCreator,OSType *PrefType,Str255 *thePrefsFilename,
  431.     long *PrefsRecSize,short *thePrefsFormatRevision)
  432. {
  433.  
  434. *PrefCreator = PrefsCreator;
  435. *PrefType = PrefsType;
  436. PStrCopy((Str255 *)PrefsFileName,thePrefsFilename);
  437. *PrefsRecSize = sizeof(PrefsRec);
  438. *thePrefsFormatRevision = PrefsFormatRevision;
  439. }
  440.  
  441. /* ======================================================= */
  442.  
  443. /* Routine: ReadPrefsPrivate */
  444. /* Purpose: Read the prefs ourselves */
  445.  
  446. void CmmPreferences::ReadPrefsPrivate(short PrefsRefNum)
  447. {
  448. }
  449.  
  450. /* ======================================================= */
  451.  
  452. /* Routine: UGetPreferences */
  453. /* Purpose: Get the preferences from the Prefs record already read in */
  454.  
  455. void CmmPreferences::UGetPreferences(Handle thePrefsH)
  456. {
  457. PrefsHRec thePrefs;
  458.  
  459.  
  460. thePrefs = (PrefsHRec)thePrefsH;
  461. theWindowLocRec = (*thePrefs)->theWindowLocRec;    /* Get the window location data */
  462. /* Use the form:   xxxx = (*thePrefs)->xxxx;    */
  463. }
  464.  
  465. /* ======================================================= */
  466.  
  467. /* Routine: USetPreferences */
  468. /* Purpose: Set new preferences, to be written out to the file */
  469.  
  470. void CmmPreferences::USetPreferences(Handle thePrefsH)
  471. {
  472. PrefsHRec thePrefs;
  473.  
  474.  
  475. thePrefs = (PrefsHRec)thePrefsH;
  476. (*thePrefs)->FormatRevision = PrefsFormatRevision;    /* Version number */
  477. (*thePrefs)->theWindowLocRec = theWindowLocRec;        /* Save the window location data */
  478. /* Use the form:   (*thePrefs)->xxxx = xxxx;    */
  479. }
  480.  
  481. /* ======================================================= */
  482.  
  483. /* Routine: GetPreferences */
  484. /* Purpose: Get the preferences */
  485.  
  486. void CmmPreferences::GetPreferences()
  487. {
  488. short        foundVRefNum,PrefsRefNum,FormatRevision,thePrefsFormatRevision;
  489. long        result,foundDirID,DataSize,count,PrefsRecSize;
  490. OSErr        theError;
  491. Boolean        GotPreferences,HasFindFolder;
  492. Str255        thePrefsFilename;
  493. Handle        PrefsHandle;
  494. FSSpec        PrefsFSSpec;
  495. OSType        PrefCreator,PrefType;
  496. SysEnvRec    theEnv;
  497.  
  498.  
  499. /* Get parameters to use */
  500. this->GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  501.  
  502. GotPreferences = false;                                /* No prefs yet */
  503. HasFindFolder = false;                                /* No FindFolder routine avail yet */
  504. PrefsRefNum = 0;                                    /* No prefs file yet */
  505.  
  506. if (Has.Gestalt)                                    /* Must have Gestalt */
  507.     {
  508.     theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  509.     if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))
  510.         HasFindFolder = true;
  511.  
  512.     if (HasFindFolder)                                /* Must have FindFolder */
  513.         {
  514.         theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);/* Get preference folder */
  515.         if (theError == 0)
  516.             {
  517.             theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  518.             if (theError == fnfErr)                    /* File not found */
  519.                 theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  520.             theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  521.             }
  522.         }
  523.     else
  524.         {
  525.         theError = SysEnvirons(1,&theEnv);            /* Get volume environs */
  526.         theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  527.         if (theError == fnfErr)                        /* File not found */
  528.             {
  529.             theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  530.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  531.             }
  532.         }
  533.  
  534.     if (theError == 0)
  535.         {
  536.         theError = GetEOF(PrefsRefNum,&DataSize);    /* See if data in the file */
  537.         if (DataSize > 0)                            /* Must have data in the file to go on */
  538.             {
  539.             count = 2;                                /* Revision number size */
  540.             theError = FSRead(PrefsRefNum,&count,&FormatRevision);/* Get revision number */
  541.             theError = SetFPos(PrefsRefNum,fsFromStart,0);/* Beginning again */
  542.  
  543.             if ((FormatRevision == thePrefsFormatRevision) && (PrefsRecSize > 0))/* Only do if up to date revision */
  544.                 {
  545.                 PrefsHandle = NewHandleClear(PrefsRecSize);/* Get space for the prefs */
  546.                 if (PrefsHandle != nil)                /* Make sure we got our little tiny handle */
  547.                     {
  548.                     HLock(PrefsHandle);                /* Lock this for safety */
  549.                     count = PrefsRecSize;            /* See how much data to read */
  550.                     theError = FSRead(PrefsRefNum,&count,*PrefsHandle);/* Read it on in */
  551.                     if (theError == 0)
  552.                         this->UGetPreferences(PrefsHandle);/* Let the user get the prefs */
  553.  
  554.                     GotPreferences = true;            /* Got our preferences */
  555.                     HUnlock(PrefsHandle);            /* OK to unlock now */
  556.                     DisposeHandle(PrefsHandle);        /* All done with this record  */
  557.                     }
  558.                 }
  559.             else
  560.                 this->ReadPrefsPrivate(PrefsRefNum);    /* Let the user read the prefs himself */
  561.             }
  562.         if (PrefsRefNum != 0)                        /* Done with the file , close it */
  563.             theError = FSClose(PrefsRefNum);
  564.         }
  565.     }
  566.  
  567. if (!GotPreferences )                                /* If we did not get prefs , use default values */
  568.     this->SetPreferences();                            /* Set the default values */
  569.  
  570. }
  571.  
  572. /* ======================================================= */
  573.  
  574. /* Routine: SetPreferences */
  575. /* Purpose: Set new preferences */
  576.  
  577. void CmmPreferences::SetPreferences()
  578. {
  579. Str255        thePrefsFilename;
  580. OSErr        theError;
  581. long        result,foundDirID,count,PrefsRecSize;
  582. short        foundVRefNum,PrefsRefNum,thePrefsFormatRevision;
  583. Handle        PrefsHandle;
  584. Boolean        HasFindFolder;
  585. FSSpec        PrefsFSSpec;
  586. OSType        PrefCreator,PrefType;
  587. SysEnvRec    theEnv;
  588.  
  589.  
  590. /* Get parameters to use */
  591. this->GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  592. PrefsRefNum = 0;
  593.  
  594. PrefsHandle = NewHandleClear(PrefsRecSize);            /* Allocate the prefs space holder */
  595.  
  596. if (PrefsHandle != nil)
  597.     {
  598.     HLock(PrefsHandle);                                /* Lock for safety */
  599.  
  600.     this->USetPreferences(PrefsHandle);                /* Let the user set the other pref values */
  601.  
  602.     HasFindFolder = false;
  603.     if (Has.Gestalt)                                /* Must have Gestalt */
  604.         {
  605.         theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  606.         if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))/* See if FindFolder */
  607.             HasFindFolder = true;
  608.  
  609.         if (HasFindFolder )                            /* Must have FindFolder */
  610.             {
  611.             theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);
  612.             if (theError == 0)
  613.                 {
  614.                 theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  615.                 if (theError == fnfErr)                /* File not found */
  616.                     theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  617.                 theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  618.                 }
  619.             }
  620.         else
  621.             {
  622.             theError = SysEnvirons(1,&theEnv);        /* Get volume environs */
  623.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  624.             if (theError == fnfErr)                    /* File not found */
  625.                 {
  626.                 theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  627.                 theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  628.                 }
  629.             }
  630.  
  631.         if (theError == 0)
  632.             {
  633.             count = PrefsRecSize;
  634.             theError = FSWrite(PrefsRefNum,&count,*PrefsHandle);/* Write new prefs */
  635.             theError = SetEOF(PrefsRefNum,count);    /* Reset EOF */
  636.  
  637.             if (PrefsRefNum != 0)
  638.                 theError = FSClose(PrefsRefNum);    /* Close file */
  639.  
  640.             HUnlock(PrefsHandle);
  641.             DisposeHandle(PrefsHandle);                /* Done with Prefs handle */
  642.             }
  643.         }
  644.     }
  645.  
  646. }
  647.  
  648. /* ======================================================= */
  649.  
  650. void PositionWindow(WindowPtr theWindow,Point  WantLocation,Point DefaultPosition)
  651. {
  652. Boolean        FitsOK;
  653. Rect        WindowRect;
  654. GrafPtr        theDesktopPort;
  655. RgnHandle    theRgn,the2Rgn;
  656.  
  657.  
  658. FitsOK = false;                                        /*Init to not on current screen(s) */
  659. WindowRect = theWindow->portRect;                    /* Save the rect to get the size */
  660. OffsetRect(&WindowRect,-WindowRect.left,-WindowRect.top);    /* Offset to 0,0 */
  661. OffsetRect(&WindowRect,WantLocation.h,WantLocation.v);        /* Offset to wanted location */
  662.  
  663. GetWMgrPort(&theDesktopPort);                        /* Get the screen */
  664.  
  665. theRgn = NewRgn();                                    /* Make temp regions */
  666. the2Rgn = NewRgn();
  667. RectRgn(theRgn,&WindowRect);                        /* First region to our window rectangle on the screen */
  668. SectRgn(theRgn,theDesktopPort->visRgn,the2Rgn);        /* Do the intersection with the screen and window */
  669. if (EqualRgn(theRgn,the2Rgn))                        /* If all of window in the screen area then ... */
  670.     FitsOK = true;                                    /* ...all of the window is on the screen area */
  671. if (EmptyRgn(the2Rgn))
  672.     FitsOK = false;
  673.  
  674. DisposeRgn(theRgn);                                    /* Dispose of temp regions */
  675. DisposeRgn(the2Rgn);
  676. if ((FitsOK) && ((WantLocation.h != 0) || (WantLocation.v != 0)))    /* If all of window in the screen area then ... */
  677.     MoveWindow(theWindow,WantLocation.h,WantLocation.v,false);    /* Move to saved location */
  678. else
  679.     MoveWindow(theWindow,DefaultPosition.h,DefaultPosition.v,false); /* Move to original location */
  680. }
  681.  
  682. /* ======================================================= */
  683.  
  684. /* Routine: PStrCopy */
  685. /* Purpose: Copy Pascal strings */
  686.  
  687. void PStrCopy(Str255 *SourceString, Str255 *DestString)/* Copy Pascal strings */
  688. {
  689.  
  690.  
  691. *DestString[0] = *SourceString[0];                    /* Get the string size */
  692. if (*DestString[0] != 0)                            /* Do if there is anything in the string */
  693.     BlockMove(SourceString,DestString,*DestString[0]+1);
  694. }
  695.  
  696. /* ======================================================= */
  697.  
  698. /* Routine: PStrCat */
  699. /* Purpose: Concat Pascal strings */
  700.  
  701. void PStrCat(Str255 *SourceString, Str255 *DestString)/* Concat Pascal strings */
  702. {
  703. short    OldDestLength,NewDestLength,SizeFromSource;
  704.  
  705.  
  706. OldDestLength = *DestString[0];                        /* Get the string old length */
  707. SizeFromSource = *SourceString[0];                    /* Get the source length */
  708. NewDestLength = OldDestLength + SizeFromSource;        /* Get the string new length */
  709. if (NewDestLength > 255)                            /* Compare to length of the final string */
  710.     {
  711.     NewDestLength = 255;                            /* The string final length */
  712.     SizeFromSource = 255 - OldDestLength;            /* The string final length */
  713.     }
  714.  
  715. *DestString[0] = NewDestLength;                        /* Set the string length */
  716. if (SizeFromSource > 0)                                /* Do if there is anything in the string */
  717.     BlockMove((Ptr)((long)SourceString + 1L),(Ptr)((long)DestString+OldDestLength+1L),SizeFromSource);
  718. }
  719.  
  720. /* ======================================================= */
  721.  
  722. /* Routine: PStrCmp */
  723. /* Purpose: Compare Pascal strings for exact match, case sensitive */
  724.  
  725. Boolean PStrCmp(StringPtr Source1String,StringPtr Source2String)/* Compare Pascal strings */
  726. {
  727. short        theLength,Index;
  728. Boolean        theSame;
  729.  
  730.  
  731. theSame = false;                                    /* Init to different */
  732. theLength = *Source1String++;                        /* Get length of one string */
  733. if (theLength == *Source2String++)                    /* Compare to length of other string, easy and quick check */
  734.     {
  735.     theSame = true;                                    /* Init to same, now we will check each character */
  736.     for (Index=1; Index <= theLength; Index++)        /* Compare to length of other string, easy and quick check */
  737.         {
  738.         if (*Source1String++ != *Source2String++)    /* See if this character is the same */
  739.             theSame = false;                        /* Different */
  740.         }
  741.     }
  742.  
  743. return(theSame);
  744. }
  745.  
  746. /* ======================================================= */
  747.  
  748. /* Routine: GetUserEvent */
  749. /* Purpose: See if any user events are available */
  750.  
  751. void GetUserEvent(UserEventPRec TheUserEvent)
  752. UserEventHRec    NextUserEvent;                        /* The next user event */
  753.  
  754.  
  755. TheUserEvent->ID = UserEvent_None;                    /* Set ID to no events are available */
  756. if (UserEventList != NIL)                            /* Get first entry in the list */
  757.     {
  758.     HLock((Handle)UserEventList);                    /* Lock for safety */
  759.     TheUserEvent->ID = (*UserEventList)->ID;        /* The event ID */
  760.     TheUserEvent->ID2 = (*UserEventList)->ID2;        /* The optional ID */
  761.     TheUserEvent->Data1 = (*UserEventList)->Data1;    /* The optional data */
  762.     TheUserEvent->Data2 = (*UserEventList)->Data2;    /* The optional data */
  763.     TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  764.     NextUserEvent = (*UserEventList)->Next;            /* The next list */
  765.  
  766.     DisposHandle((Handle)UserEventList);            /* Remove this list item */
  767.     UserEventList = NextUserEvent;                    /* Make the next item the new first item */
  768.     }
  769. }
  770.  
  771. /* ======================================================= */
  772.  
  773. /* Routine: Add_UserEvent */
  774. /* Purpose: Add a user event */
  775.  
  776. void Add_UserEvent(short ID1,short  ID2,long Data1,long Data2,Handle  theHandle)
  777. UserEventHRec    NewUserEvent;                        /* The new user event */
  778. UserEventHRec    theUserEvent;                        /* The user event */
  779.  
  780.  
  781. NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  782. if (NewUserEvent != NIL)                            /* Only do if we got the new record */
  783.     {
  784.     HLock((Handle)NewUserEvent);                    /* Lock for safety */
  785.     (*NewUserEvent)->ID = ID1;                        /* The event ID */
  786.     (*NewUserEvent)->ID2 = ID2;                        /* The optional ID */
  787.     (*NewUserEvent)->Data1 = Data1;                    /* The optional data */
  788.     (*NewUserEvent)->Data2 = Data2;                    /* The optional data */
  789.     (*NewUserEvent)->theHandle = theHandle;            /* The optional handle */
  790.     (*NewUserEvent)->Next = NIL;                    /* No next item after this one */
  791.  
  792.     if (UserEventList == NIL)                        /* See if anyone is in the list yet */
  793.         UserEventList = NewUserEvent;                /* Make this one the first in the list */
  794.     else
  795.         {
  796.         theUserEvent = UserEventList;                /* Get the first one */
  797.         while ((*theUserEvent)->Next != NIL)        /* Get the next one */
  798.             {
  799.             theUserEvent = (*theUserEvent)->Next;
  800.             }
  801.         (*theUserEvent)->Next = NewUserEvent;        /* Tack on to the end */
  802.         }
  803.     }
  804. }
  805.  
  806. /* ======================================================= */
  807.  
  808. /* Routine: SetNameForPopup */
  809. /* Purpose: Set the title for a popup control */
  810.  
  811. void SetNameForPopup(ControlHandle theControl)
  812. Handle    theHandle;                                    /* The resource handle */
  813. ResType    theType;                                    /* Returned type */
  814. short    theID;                                        /* Returned ID */
  815. short    theMenuID;                                    /* Menu ID */
  816.  
  817.  
  818. theMenuID = GetCtlMax(theControl);                    /* Get the menu ID */
  819. theHandle = Get1Resource('MENU', theMenuID);        /* See if the resource is out there */
  820. if (theHandle != nil)                                /* See if we got the menu */
  821.     GetResInfo(theHandle,&theID,&theType,sTemp);    /* Get the title */
  822. else                                                /* Else no menu here */
  823.     sTemp[0] = 0;                                    /* Get the title */
  824. SetCTitle(theControl,sTemp);                        /* Set the title */
  825. }
  826.  
  827. /* ======================================================= */
  828.  
  829. /* Routine: Make_A_List */
  830. /* Purpose: This is a routine used to make a new list */
  831.  
  832. void Make_A_List(ListHandle *theList,Rect *theListRect,WindowPtr theWindow,short theStringResourceID,
  833.     short theSize,short theFont,Style theStyle,Boolean InDialog)
  834. {
  835. Point    cSize;                                        /* Use to point to proper row */
  836. Handle    theHandle;                                    /* Temp Handle */
  837. Rect    dataBounds;
  838.  
  839.  
  840. TextSize(theSize);                                    /* Set text size */
  841. TextFont(theFont);                                    /* Set text font */
  842. TextFace(theStyle);                                    /* Set text style */
  843.  
  844. tempRect = *theListRect;
  845. tempRect.right = tempRect.right - 15;                /* Go inside the scroll bar area */
  846. SetRect(&dataBounds, 0, 0, 1, 0);                    /* Make the empty list */
  847. cSize.h = theListRect->right - 15 - theListRect->left;/* Get the width of the list */
  848. cSize.v = 0;                                        /* Set the HEIGHT of each list element, based on font selected */
  849.  
  850. *theList = LNew(&tempRect, &dataBounds, cSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE);/* Create the list */
  851. (**theList)->selFlags = lOnlyOne + lNoNilHilite;    /* Set for only one active item at a time */
  852. LDoDraw(FALSE,*theList);                            /* Do not Draw this list structure */
  853.  
  854. theHandle = Get1Resource('STR#',theStringResourceID);/* See if any strings */
  855. if (theHandle != NIL)
  856.     {
  857.     cSize.h = 0;                                    /* Point to the correct column, starts at zero */
  858.     cSize.v = -1;                                    /* Point to the correct row, starts at zero */
  859.     do
  860.         {
  861.         GetIndString(sTemp, theStringResourceID, cSize.v + 2);/* Get the new string */
  862.         if (sTemp[0] > 0)
  863.             Add_List_String(sTemp, *theList, &cSize);/* Add in the new string */
  864.         }
  865.     while (sTemp[0] != 0);                            /* Add all the strings in this resource */
  866.     }
  867.  
  868. LDoDraw(TRUE,*theList);                                /* Draw this list structure */
  869. cSize.h = 0;                                        /* All elements are in column 0e */
  870. cSize.v = 0;                                         /* Select the first list element */
  871. LSetSelect(TRUE, cSize,*theList);
  872.  
  873. if (InDialog)
  874.     TextFont(systemFont);                            /* Back to the system font */
  875. else
  876.     TextFont(applFont);                                /* Back to the application font */
  877. TextSize(12);                                        /* Back to the application size */
  878. TextFace(0);                                        /* Set text style */
  879. }
  880.  
  881. /* ======================================================= */
  882.  
  883. void Play_The_Sound(short ResID)
  884. {
  885. Handle        ResHandle;                                /* The sound resource handle */
  886. short        SndResourceID;                            /* Sound resource ID */
  887. Str255        SndName;                                /* Sound name*/
  888. ResType        theType;                                /* Resource type */
  889. OSErr        MyErr;                                    /* Error flag */
  890.  
  891.  
  892. ResHandle = Get1Resource('snd ', ResID);            /* See if the resource is out there */
  893. if (ResHandle != NIL)                                /* Only do if we got the sound */
  894.     {
  895.     GetResInfo(ResHandle,&SndResourceID,&theType,SndName);
  896.     #if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
  897.     MyErr = SndPlay(NIL,ResHandle,FALSE);
  898. #else
  899.     MyErr = SndPlay(NIL,(SndListHandle)ResHandle,FALSE);
  900. #endif
  901.     ReleaseResource(ResHandle);
  902.     }
  903. }
  904.  
  905. /* ======================================================= */
  906.  
  907. /* Routine: Add_List_String */
  908. /* Purpose: This is a routine used to add strings to an existing list */
  909.  
  910. void Add_List_String(Str255 theString,ListHandle theList,Point *cSize) 
  911. {
  912. short    theRow;                                        /* The Row that we are adding */
  913.  
  914.  
  915. if (theList != NIL)  
  916.     {
  917.     cSize->h = 0;                                    /* Point to the correct column */
  918.     theRow = LAddRow(1, 32000, theList);            /* Add another row at the end of the list */
  919.     cSize->v = theRow;                                /* Point to the row just added */
  920.     LSetCell(&theString[1], theString[0], *cSize,theList);/* Place string in row just created */
  921.     }
  922. }
  923.  
  924. /* ======================================================= */
  925.  
  926. /* Routine: Get_TE_String */
  927. /* Purpose: This is a routine used to get a string from a TE area, limited to 250 characters */
  928.  
  929. void Get_TE_String(TEHandle theTEArea,Str255 *theString)
  930. short Index;                                        /* Use to loop thru the characters */
  931. short TitleLength;                                    /* Number of characters to do */
  932. CharsHandle theCharsHandle;                            /* Used to get global edit text */
  933. Ptr theStringPtr;                                    /* Pointer to the string, byte level */
  934. Ptr theTECharPtr;                                    /* Pointer to the string, byte level */
  935.  
  936.  
  937. theCharsHandle = TEGetText(theTEArea);                /* Get the character handle */
  938. HLock ( ( Handle ) theCharsHandle );                /* Lock it for safety */
  939. theTECharPtr = (Ptr)*theCharsHandle;                /* Get string Ptr */
  940. TitleLength = (*theTEArea)->teLength;                /* Get the number of characters */
  941. *theString[0] = 0;                                    /* Start with an empty string */
  942. if (TitleLength > 0) 
  943.     {
  944.     theStringPtr = (Ptr)((long)theString + (long)1);/* Start of the string data */
  945.     if (TitleLength > 250) 
  946.         TitleLength = 250;
  947.     for (Index = 0; Index < TitleLength; Index++)
  948.         *theStringPtr++ = (char)(*theTECharPtr++);
  949.     *theString[0] = TitleLength;
  950.     }
  951. }
  952.  
  953. /* ======================================================= */
  954.  
  955. /* Routine: Make_TE_Area */
  956. /* Purpose: This is a routine used to create a TE area */
  957.  
  958. void Make_TE_Area(TEHandle *theTEArea,Rect *Position,short theFontSize,
  959.     short theFont,short DefaultStringID)
  960. {
  961. FontInfo    ThisFontInfo;                            /* Use to get the font data */
  962.  
  963.  
  964. TextSize(theFontSize);                                /* Set the size */
  965. TextFont(theFont);                                    /* Set the font */
  966. GetFontInfo(&ThisFontInfo);                            /* Get Ascent height for positioning */
  967.  
  968. tempRect = *Position;                                /* Get the rect */
  969. FrameRect(&tempRect);                                /* Frame this TE area */
  970. InsetRect(&tempRect, 3, 3);                            /* Indent for TE inside of box */
  971. *theTEArea = TENew(&tempRect, &tempRect);            /* Create the TE area */
  972. if (theInput != NIL)                                /* See if there is already a TE area */
  973.     TEDeactivate(theInput);                            /* Yes, so turn it off */
  974.  
  975. theInput = *theTEArea;                                /* Activate the TE area */
  976. GetIndString(sTemp, DefaultStringID, 1);            /* Get the default string */
  977. TESetText(&sTemp[1], sTemp[0], theInput);            /* Place default text in the TE area */
  978. TEActivate(theInput);                                /* Make the TE area active */
  979.  
  980. TextSize(12);                                        /* Set the size */
  981. TextFont(applFont);                                    /* Set the font */
  982. }
  983.  
  984. /* ======================================================= */
  985.  
  986. /* Routine: Plot_Sicn */
  987. /* Purpose: This is a routine used to plot an Sicn, small 16x16 icon */
  988.  
  989. void Plot_Sicn(short theSicnID,Rect *Position)
  990. typedef struct SmallIconRec{
  991.     long    theIcon[16];
  992. }*SmallIconPtr,**SmallIconHand;
  993.  
  994. SmallIconHand    SmallIcon;                            /* Handle to the SICN resource */
  995. BitMap            theBitMap;                            /* Bitmap for plotting */
  996. Rect            sourceRect, DestRect;                /* Rects for plotting */
  997. GrafPtr            thePort;                            /* Port to draw on to */
  998.  
  999.  
  1000. SmallIcon = (SmallIconHand)GetResource('SICN', theSicnID);/* Get the resource */
  1001. if (SmallIcon != NIL)                                /* Do if there is a resource */
  1002.     {
  1003.     SetRect(&sourceRect, 0, 0, 16, 16);                /* Sicns are 16 x 16 */
  1004.     DestRect = *Position;                            /* Destination */
  1005.     theBitMap.baseAddr = (Ptr)&(*SmallIcon)->theIcon;/* Base address of the bitmap */
  1006.     theBitMap.rowBytes = 2;                            /* 2*8 = 16 */
  1007.     theBitMap.bounds = sourceRect;                    /* Source rect size */
  1008.     GetPort(&thePort);                                /* Get the current port */
  1009.     CopyBits(&theBitMap, &thePort->portBits, &sourceRect, &DestRect, srcCopy, NIL);/* Plot it */
  1010.     }
  1011. }
  1012.  
  1013. /* ======================================================= */
  1014.  
  1015. /* Routine: HandleWScrollBar */
  1016. /* Purpose: This is a routine used to handle a scrollbar */
  1017.  
  1018. void HandleWScrollBar (Point myPt,short code,short Increment,short LIncrement,ControlHandle theControl)
  1019. {
  1020. short    theValue;                                    /* Value of the scrollbar */
  1021. long    MaxTick;                                    /* Timer used for repeat scrolling */
  1022. Boolean    FirstTime;                                    /* Flag to start scrolling */
  1023. short    Start,Stop;
  1024.  
  1025.  
  1026. Start = GetCtlMin(theControl);
  1027. Stop = GetCtlMax(theControl);
  1028.  
  1029. FirstTime = TRUE;                                    /* Do the scroll the first time also */
  1030. while (StillDown() || FirstTime)                    /* Do the scroll as long as the button is down */
  1031.     {                                                /* Timer used for repeat scrolling */
  1032.     FirstTime = FALSE;                                /* Do the scroll the first time only unless auto */
  1033.     HiliteControl(theControl, code);                /* Darken the arrow */
  1034.     theValue = GetCtlValue(theControl);                /* Get current state */
  1035.  
  1036.     if (code == inUpButton)                            /* See if in the up/left arrow */
  1037.         {
  1038.         theValue = theValue - Increment;            /* Subtract the single decrement */
  1039.         if (theValue < Start)                        /* Check for boundary conditions */
  1040.             theValue = Start;                        /* Bump at the start value */
  1041.         }
  1042.  
  1043.     if (code == inDownButton)                        /* See if in the down/right arrow */
  1044.         {
  1045.         theValue = theValue + Increment;            /* Add the single increment */
  1046.         if (theValue > Stop)                         /* Check for boundary conditions */
  1047.             theValue = Stop;                        /* Bump at the stop value */
  1048.         }
  1049.  
  1050.     if (code == inPageUp)                            /* See if in the up/left grey area */
  1051.         {
  1052.         theValue = theValue - LIncrement;            /* Subtract the page increment */
  1053.         if (theValue < Start)                         /* Check for boundary conditions */
  1054.             theValue = Start;                        /* Bump at the Start value */
  1055.         }
  1056.  
  1057.     if (code == inPageDown)                            /* See if in the down/right grey area */
  1058.         {
  1059.         theValue = theValue + LIncrement;            /* Add the page increment */
  1060.         if (theValue > Stop)                        /* Check for boundary conditions */
  1061.             theValue = Stop;                        /* Bump at the Stop value */
  1062.         }
  1063.  
  1064.     if (code == inThumb)                            /* See if in the drag box area */
  1065.         {
  1066.         code = TrackControl(theControl, myPt, NIL);    /* Let the OS drag it around */
  1067.         theValue = GetCtlValue(theControl);            /* Get current state */
  1068.         }
  1069.  
  1070.     SetCtlValue(theControl, theValue);                /* Set new state */
  1071.  
  1072.     MaxTick = TickCount() + 9;                        /* Time delay for auto-scroll */
  1073.     do                                                /* Start of delay routine */
  1074.         {}
  1075.     while ((Button()) && (TickCount() < MaxTick));    /* Exit when time up or mouse button up */
  1076.     HiliteControl(theControl, 0);                    /* Lighten the arrow */
  1077.     }                                                /* End for StillDown */
  1078. }
  1079.  
  1080. /* ======================================================= */
  1081.  
  1082. StandardFileReply    myStdFileReply;                    /* For use in the filter routine */
  1083.  
  1084. /* Routine: mySelectDlgFilter */
  1085. /* Purpose: Filter routine for Select Volume routine */
  1086.  
  1087. static pascal short mySelectDlgFilter (short item,DialogPtr theDialog,Ptr myDataPtr)
  1088. {
  1089. short            theItem;
  1090. short            theWidth;
  1091. short            theNameWidth;
  1092. short            DType;
  1093. Handle            DItem;
  1094. ControlHandle    CItem;
  1095. Str255            sTemp;
  1096. Str255            theName;
  1097. Str255            LastChar;
  1098. Point            cSize;
  1099. Rect            dataBounds;
  1100. Boolean            NamesAreSame;
  1101.  
  1102.  
  1103. theItem = item;
  1104.  
  1105. if (theItem == sfHookNullEvent)
  1106.     {
  1107.     NamesAreSame = PStrCmp((StringPtr)&Last_Name,(StringPtr)&myStdFileReply.sfFile.name);
  1108.     if ((Last_vRefNum != myStdFileReply.sfFile.vRefNum) || (Last_parID != myStdFileReply.sfFile.parID) || (!NamesAreSame))
  1109.         theItem = sfItemFileListUser;
  1110.     }
  1111. else
  1112.     theItem = theItem;
  1113.  
  1114. if (theItem == sfItemFileListUser)
  1115.     {
  1116.     if ((Last_vRefNum != myStdFileReply.sfFile.vRefNum) || (Last_parID != myStdFileReply.sfFile.parID) || (Last_Name != myStdFileReply.sfFile.name))
  1117.         {
  1118.         Last_vRefNum = myStdFileReply.sfFile.vRefNum;
  1119.         Last_parID = myStdFileReply.sfFile.parID;
  1120.         PStrCopy((Str255 *)myStdFileReply.sfFile.name,&Last_Name);
  1121.         GetDItem(theDialog, 10, &DType, &DItem, &tempRect);
  1122.         theWidth = tempRect.right - tempRect.left - 10;
  1123.         PStrCopy((Str255 *)"\pSelect '",&sTemp );
  1124.         theWidth = theWidth - StringWidth(sTemp);
  1125.         PStrCopy((Str255 *)myStdFileReply.sfFile.name,&theName);
  1126.         theNameWidth = StringWidth(theName);
  1127.         if (theNameWidth > theWidth)
  1128.             {
  1129.             LastChar[0] = 1;
  1130.             LastChar[1] = theName[theName[0]];
  1131.             PStrCopy(&theName,&sTemp); 
  1132.             PStrCat((Str255 *)"\p...",&sTemp);
  1133.             PStrCat(&LastChar,&sTemp); 
  1134.             while (StringWidth(sTemp) > (theWidth - 5))
  1135.                 {
  1136.                 theName[0] = theName[0] - 1;
  1137.                 PStrCopy(&theName,&sTemp); 
  1138.                 PStrCat((Str255 *)"\p...",&sTemp);
  1139.                 PStrCat(&LastChar,&sTemp); 
  1140.                 }
  1141.             PStrCat((Str255 *)"\p...",&theName);
  1142.             PStrCat(&LastChar,&theName); 
  1143.             }
  1144.  
  1145.         PStrCopy((Str255 *)"\pSelect '", &sTemp );
  1146.         PStrCat(&theName,&sTemp); 
  1147.         PStrCat((Str255 *)"\p'",&sTemp);
  1148.         CItem = (ControlHandle)DItem;                /* Change dialog handle to control handle */
  1149.         SetCTitle(CItem, sTemp);
  1150.         if (myStdFileReply.sfIsFolder || myStdFileReply.sfIsVolume)
  1151.             HiliteControl(CItem, 0);
  1152.         else
  1153.             HiliteControl(CItem,255);
  1154.         }
  1155.     }
  1156. else if (theItem == 10)
  1157.     theItem = sfItemOpenButton;
  1158.  
  1159. return(theItem);
  1160. }
  1161.  
  1162. /* ======================================================= */
  1163.  
  1164. /* Routine: mySelectCustomFileFilter */
  1165. /* Purpose: Filter file routine for Select Volume routine */
  1166.  
  1167. static pascal Boolean mySelectCustomFileFilter (CInfoPBPtr pb,Ptr myDataPtr)
  1168. {
  1169. Boolean        HideTheItem;
  1170. HFileInfo    *FileRecPtr;
  1171.  
  1172.  
  1173. HideTheItem = true;
  1174. FileRecPtr = (HFileInfo *)pb;
  1175. if ((FileRecPtr->ioFlAttrib & 0x0010) != 0)            /* Doing Folder */
  1176.     HideTheItem = false;
  1177.  
  1178. return(HideTheItem);
  1179. }
  1180.  
  1181. /* ======================================================= */
  1182.  
  1183. /* Routine: Init */
  1184. /* Purpose: Init */
  1185.  
  1186. void CmmFiles::Init()
  1187. {
  1188. }
  1189.  
  1190. /* ======================================================= */
  1191.  
  1192. /* Routine: Close_The_Input_File */
  1193. /* Purpose: Close The Input File */
  1194.  
  1195. void CmmFiles::Close_The_Input_File()
  1196. {
  1197. OSErr        ErrorCode;
  1198.  
  1199.  
  1200. ErrorCode = FSClose(this->Files.inputRefNum);                /* Invalidate the refnum */
  1201. this->Files.inputRefNum = 0;                                /* Close the file */
  1202. }
  1203.  
  1204. /* ======================================================= */
  1205.  
  1206. /* Routine: Close_The_Output_File */
  1207. /* Purpose: Close the output file */
  1208.  
  1209. void CmmFiles::Close_The_Output_File()
  1210. {
  1211. OSErr        ErrorCode;
  1212.  
  1213.  
  1214. ErrorCode = FSClose(this->Files.outputRefNum);            /* Invalidate the refnum */
  1215. this->Files.outputRefNum = 0;                                /* Close the file */
  1216. }
  1217.  
  1218. /* ======================================================= */
  1219.  
  1220. /* Routine: Open_The_File */
  1221. /* Purpose: Open The File */
  1222.  
  1223. void CmmFiles::Open_The_File()
  1224. {
  1225. }
  1226.  
  1227. /* ======================================================= */
  1228.  
  1229. /* Routine: Select_Volume */
  1230. /* Purpose: Select Volume */
  1231.  
  1232. void CmmFiles::Select_Volume()
  1233. {
  1234. }
  1235.  
  1236. /* ======================================================= */
  1237.  
  1238. /* Routine: Save_The_File */
  1239. /* Purpose: Save The File */
  1240.  
  1241. void CmmFiles::Save_The_File()
  1242. {
  1243. }
  1244.  
  1245. /* ======================================================= */
  1246. /* ======================================================= */
  1247.  
  1248. /* Routine: Do_The_Select_Volume */
  1249. /* Purpose: This is a routine used to select a user selected folder or volume */
  1250. /* Return TRUE for opened the file OK, else return FALSE */
  1251.  
  1252. Boolean CmmFiles::Do_The_Select_Volume(FSSpec *theFile)        /* Select a volume */
  1253. {
  1254. short    Screen_Width;                                /* Size of the current screen */
  1255. short    Screen_Height;                                /* Size of the current screen */
  1256. Point    Where;                                        /* Used for placing the SF dialog */
  1257. Boolean    OpenedOK;                                    /* Flag to return */
  1258. FileFilterYDUPP    gMyFileFilterYDUPP;
  1259. DlgHookYDUPP    gMyDlgHookYDUPP;
  1260.  
  1261.  
  1262. gMyFileFilterYDUPP = NewFileFilterYDProc(mySelectCustomFileFilter);
  1263. gMyDlgHookYDUPP = NewDlgHookYDProc(mySelectDlgFilter);
  1264.  
  1265. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1266. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1267.  
  1268. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1269. Where.v = (Screen_Height / 4) - (104 / 2);
  1270. if (Where.v < 60)
  1271.     Where.v = 60;
  1272. InitCursor();
  1273. this->Files.typeList[0] = 'GRC ';
  1274. Last_vRefNum = -2;
  1275. Last_parID = -2;
  1276. CustomGetFile(gMyFileFilterYDUPP,0,this->Files.typeList,&myStdFileReply,
  1277.     512,Where,gMyDlgHookYDUPP, nil, nil, nil, nil);
  1278.  
  1279. this->Files.theStdFileReply = myStdFileReply;
  1280.  
  1281. OpenedOK = false;                                    /* Init to did not open the file */
  1282. if (this->Files.theStdFileReply.sfGood)                    /* Only do if the user did not cancel */
  1283.     {
  1284.     *theFile = this->Files.theStdFileReply.sfFile;        /* Save the FSSpec */
  1285.     BlockMove((Ptr)&this->Files.theStdFileReply.sfFile.name,&this->Files.inputFileName,
  1286.         this->Files.theStdFileReply.sfFile.name[0]+1);
  1287.     OpenedOK = true;                                /* We selected a folder */
  1288.     }
  1289. else
  1290.     this->Files.inputFileName[0] = 0;                        /* No name for a folder */
  1291.  
  1292. return(OpenedOK);
  1293. }
  1294.  
  1295. /* ======================================================= */
  1296.  
  1297. /* Routine: Do_The_Open_File */
  1298. /* Purpose: This is a routine used to open a user selected file */
  1299. /* Return TRUE for opened the file OK, else return FALSE */
  1300.  
  1301. Boolean CmmFiles::Do_The_Open_File (short NumberOfTypes,short *theVolRefNum,ProcPtr fileFilter,
  1302.     ProcPtr dlgHook)
  1303. {
  1304. short    Screen_Width;                                /* Size of the current screen */
  1305. short    Screen_Height;                                /* Size of the current screen */
  1306. Point    Where;                                        /* Used for placing the SF dialog */
  1307. Boolean    OpenedOK;                                    /* Flag to return */
  1308. OSErr    ErrorCode;
  1309. SFReply    Reply;                                        /* Temp record for making SFGetFile call */
  1310. SFTypeList    typeList;
  1311. FileFilterUPP    gMyFileFilterUPP;
  1312. DlgHookUPP        gMyDlgHookUPP;
  1313.  
  1314.  
  1315. gMyFileFilterUPP = NewFileFilterProc(fileFilter);
  1316. gMyDlgHookUPP = NewDlgHookProc(dlgHook);
  1317.  
  1318. typeList[0] = this->Files.typeList[0];
  1319. typeList[1] = this->Files.typeList[1];
  1320. typeList[2] = this->Files.typeList[2];
  1321. typeList[3] = this->Files.typeList[3];
  1322.  
  1323. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1324. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1325.  
  1326. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1327. Where.v = (Screen_Height / 4) - (104 / 2);
  1328. if (Where.v < 60)
  1329.     Where.v = 60;
  1330. InitCursor();
  1331. SFGetFile(Where,(StringPtr)"/pNot used",gMyFileFilterUPP,NumberOfTypes,typeList,gMyDlgHookUPP,&Reply);
  1332.  
  1333. *theVolRefNum = 0;
  1334. this->Files.Reply = Reply;
  1335. this->Files.inputRefNum = 0;                        /* We did not open */
  1336.  
  1337. OpenedOK = false;                                    /* Init to did not open the file */
  1338. if (Reply.good)                                        /* Only do if the user did not cancel */
  1339.     {
  1340.     BlockMove((Ptr)&Reply.fName,&this->Files.inputFileName,Reply.fName[0]+1);
  1341.  
  1342.     ErrorCode = SetVol(nil,Reply.vRefNum);            /* Set to this volume for later opens */
  1343.     *theVolRefNum = Reply.vRefNum;
  1344.     OpenedOK = true;                                /* Flag that we are open OK */
  1345.     }
  1346. else
  1347.     this->Files.inputFileName[0] = 0;                /* No name for a file */
  1348.  
  1349. return(OpenedOK);
  1350. }
  1351.  
  1352. /* ======================================================= */
  1353.  
  1354. /* Routine: Do_The_Save_File */
  1355. /* Purpose: This is a routine used to save a user selected file */
  1356. /* Return TRUE for opened the file OK, else return FALSE */
  1357.  
  1358. Boolean CmmFiles::Do_The_Save_File (OSType creator,OSType fileType,Str255 *Prompt,Str255 *DefaultName,
  1359.     short *theVolRefNum,short *theRefNum,ProcPtr dlgHook)
  1360. {
  1361. short    Screen_Width;                                /* Size of the current screen */
  1362. short    Screen_Height;                                /* Size of the current screen */
  1363. Point    Where;                                        /* Used for placing the SF dialog */
  1364. Boolean    OpenedOK;                                    /* Flag to return */
  1365. OSErr    ErrorCode;
  1366. SFReply    Reply;                                        /* Temp record for making SFPutFile call */
  1367. DlgHookUPP        gMyDlgHookUPP;
  1368.  
  1369.  
  1370. gMyDlgHookUPP = NewDlgHookProc(dlgHook);
  1371.  
  1372. Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
  1373. Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
  1374.  
  1375. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1376. Where.v = (Screen_Height / 4) - (104 / 2);
  1377. if (Where.v < 60)
  1378.     Where.v = 60;
  1379. InitCursor();
  1380. SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,gMyDlgHookUPP,&Reply);
  1381.  
  1382. BlockMove((Ptr)&Reply.fName,&this->Files.outputFileName,Reply.fName[0]+1);
  1383.  
  1384. this->Files.Reply = Reply;
  1385. *theVolRefNum = this->Files.Reply.vRefNum;
  1386. *theRefNum = 0;
  1387. this->Files.outputRefNum = 0;
  1388.  
  1389. OpenedOK = false;                                    /* Init to did not open the file */
  1390. if (Reply.good)                                        /* Only do if the user did not cancel */
  1391.     {
  1392.     ErrorCode = FSDelete((StringPtr)&Reply.fName,Reply.vRefNum);    /* Delete an older file */
  1393.     ErrorCode = Create((StringPtr)&Reply.fName,Reply.vRefNum,creator,fileType);/* Create the file */
  1394.     ErrorCode = FSOpen((StringPtr)&Reply.fName,Reply.vRefNum,&this->Files.outputRefNum);/* Try to open the file */
  1395.  
  1396.     if (ErrorCode == 0)                                /* See if we opened it cleanly */
  1397.         {
  1398.         ErrorCode = SetFPos(this->Files.outputRefNum, fsFromStart, 0);/* Start at file beginning */
  1399.         ErrorCode = SetVol(nil, *theVolRefNum);        /* Set for later saves */
  1400.         *theRefNum = this->Files.outputRefNum;
  1401.         *theVolRefNum = Reply.vRefNum;
  1402.         OpenedOK = true;                            /* We opened the file OK */
  1403.         }
  1404.     else
  1405.         {
  1406.         ErrorCode = FSClose(this->Files.outputRefNum);    /* Close it if we can, safety */
  1407.         SysBeep(20);                                /* Just beep at the user, caller can do more */
  1408.         this->Files.outputRefNum = 0;                /* Make sure the refnum is inited */
  1409.         }
  1410.     }
  1411.  
  1412. return(OpenedOK);
  1413. }
  1414.  
  1415. /* ======================================================= */
  1416.  
  1417. /* Routine: Init */
  1418. /* Purpose: Init */
  1419.  
  1420. void CmmPrinting::Init()
  1421. {
  1422. this->Printing.hPrint = nil;                            /* Init to no print record yet */
  1423. this->Printing.PrinterIsOpen = false;                    /* We are not printing yet */
  1424. }
  1425.  
  1426. /* ======================================================= */
  1427.  
  1428. /* Routine: PageSetup */
  1429. /* Purpose: Do the page setup */
  1430.  
  1431. void CmmPrinting::PageSetup()
  1432. {
  1433. Boolean    Result;                                        /* Result from Setup dialog */
  1434.  
  1435.  
  1436. PrOpen();                                            /* Open the printer driver */
  1437.  
  1438. if (PrError() == noErr)                                /* Only do if no error  */
  1439.     {
  1440.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1441.         {
  1442.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1443.         HLock((Handle)Printing.hPrint);
  1444.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1445.         }
  1446.  
  1447.     Result = PrStlDialog(Printing.hPrint);            /* Setup dialog */
  1448.     PrClose();
  1449.     }
  1450. else
  1451.     SysBeep(1);
  1452. }
  1453.  
  1454. /* ======================================================= */
  1455.  
  1456. /* Routine: PrintJobSetup */
  1457. /* Purpose: Do the job setup */
  1458.  
  1459. void CmmPrinting::PrintJobSetup()
  1460. {
  1461. Boolean    Result;                                        /* Result from Setup dialog */
  1462.  
  1463.  
  1464. PrOpen();                                            /* Open the printer driver */
  1465.  
  1466. if (PrError() == noErr)                                /* Only do if no error  */
  1467.     {
  1468.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1469.         {
  1470.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1471.         HLock((Handle)Printing.hPrint);
  1472.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1473.         }
  1474.  
  1475.     Result = PrJobDialog(Printing.hPrint);            /* Setup dialog */
  1476.     PrClose();
  1477.     }
  1478. else
  1479.     SysBeep(1);
  1480. }
  1481.  
  1482. /* ======================================================= */
  1483.  
  1484. /* Routine: OpenThePrinter */
  1485. /* Purpose: Open the printer and driver for use */
  1486.  
  1487. void CmmPrinting::OpenThePrinter(Boolean *Cancelled)
  1488. {
  1489.  
  1490.  
  1491. PrOpen();                                            /* Open the printer driver */
  1492.  
  1493. if (PrError() == noErr)                                /* Only do if no error */
  1494.     {
  1495.     Printing.PrinterIsOpen = FALSE;                    /* Whether printer is open or not */
  1496.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1497.         {
  1498.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1499.         HLock((Handle)Printing.hPrint);
  1500.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1501.         }
  1502.  
  1503.     *Cancelled = PrJobDialog(Printing.hPrint);        /* Setup dialog */
  1504.     Printing.CopyCount = (*Printing.hPrint)->prJob.iCopies;    /* Get number of copies to do */
  1505.     *Cancelled = !(*Cancelled);                        /* Inverted logic */
  1506.  
  1507.     Printing.pPrPort = nil;
  1508.  
  1509.     if (*Cancelled == false)                        /* Do if they did not cancel */
  1510.         {
  1511.         Printing.PrinterIsOpen = true;                /* Whether printer is open or not */
  1512.         Printing.PageCount = 1;                        /* For adding in page number */
  1513.         Printing.LineCount = 1;                        /* For printing */
  1514.         Printing.pPrPort = PrOpenDoc(Printing.hPrint, nil, nil);/* Get printing port */
  1515.         }
  1516.     }
  1517. else
  1518.     {
  1519.     SysBeep(1);
  1520.     *Cancelled = TRUE;
  1521.     }
  1522. }
  1523.  
  1524. /* ======================================================= */
  1525.  
  1526. /* Routine: CloseThePrinter */
  1527. /* Purpose: Close the printer */
  1528.  
  1529. void CmmPrinting::CloseThePrinter()
  1530. {
  1531.  
  1532.  
  1533. if (Printing.pPrPort != nil)                        /* Do if we have a port */
  1534.     {
  1535.     PrCloseDoc(Printing.pPrPort);                    /* Clear printing port */
  1536.     Printing.pPrPort = nil;
  1537.     }
  1538.  
  1539. if (Printing.hPrint != nil)                            /* Do if we have a record */
  1540.     {
  1541.     if (((*Printing.hPrint)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
  1542.         PrPicFile(Printing.hPrint, NIL, NIL, NIL, &Printing.prStatus);/* Spool it */
  1543.     }
  1544. }
  1545.  
  1546. /* ======================================================= */
  1547.  
  1548. /* Routine: Print_The_Data */
  1549. /* Purpose: Print the data */
  1550.  
  1551. void CmmPrinting::Print_The_Data()
  1552. {
  1553. }
  1554.  
  1555. /* ======================================================= */
  1556.  
  1557. /* Routine: SetupTheItem */
  1558. /* Purpose: Setup a dialog or alert item */
  1559.  
  1560. void SetupTheItem(DialogPtr theDialog,short ItemID,Boolean SizeIt,Boolean ShowIt,
  1561.     Boolean EnableIt,Boolean SetTheMax,Rect *thePosition,long ExtraData,short StringID)
  1562. {
  1563. Rect            tempRect;                            /* Temporary rectangle */
  1564. short            DType;                                /* Type of dialog item */
  1565. Handle            DItem;                                /* Handle to the dialog item */
  1566. ControlHandle    CItem;                                /* Control handle */
  1567.  
  1568.  
  1569. GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
  1570. CItem = (ControlHandle)DItem;                        /* Change to control handle */
  1571.  
  1572. if (SizeIt)                                            /* Have to resize all CDEF connected controls */
  1573.     SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1574. *thePosition = tempRect;                            /* Pass back the zone location and size */
  1575.  
  1576. if (ExtraData != NIL)                                /* See if extra data for a CDEF */
  1577.     (*CItem)->contrlData = (Handle)ExtraData;        /* Send it */
  1578.  
  1579. if (StringID != 0)                                    /* See if a CDEF and needs the title set again*/
  1580.     {
  1581.     GetIndString(sTemp,StringID,1);                    /* Get the string */
  1582.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1583.     }
  1584.  
  1585. if (EnableIt)                                        /* See if enable or disable the zone */
  1586.     HiliteControl (CItem,0);                        /* Enable the zone */
  1587. else
  1588.     HiliteControl (CItem,255);                        /* Dim the zone */
  1589.  
  1590. if (SetTheMax)
  1591.     SetCtlMax(CItem,12345);                            /* Set the flag to the CDEF */
  1592.  
  1593. if (ShowIt)
  1594.     ShowControl(CItem);                                /* Show it to activate it */
  1595. }
  1596.  
  1597. /* ======================================================= */
  1598.  
  1599. /* Routine: CenterOnColorScreen */
  1600. /* Purpose: Center a window onto the deepest color screen */
  1601.  
  1602. void CenterOnColorScreen (WindowPtr theWindow )
  1603. {
  1604. Rect        tempRect,gdRect,temp2Rect;                /* Temporary rectangle */
  1605. GDHandle    theDevice;                                /* Graphic device */
  1606.  
  1607. if ((theWindow != NIL) && (Has.ColorQD))            /* Make sure it is safe to go ahead */
  1608.     {
  1609.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1610.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1611.  
  1612.     if (theDevice != NIL)                            /* Make sure we got a device */
  1613.         {
  1614.         gdRect = (*theDevice)->gdRect;                /* Get the device rect */
  1615.         temp2Rect = theWindow->portRect;            /* Get the window rect */
  1616.  
  1617.         tempRect.top = gdRect.top + ((gdRect.bottom-gdRect.top)/2) - ((temp2Rect.bottom-temp2Rect.top)/2);
  1618.         tempRect.left = gdRect.left + ((gdRect.right-gdRect.left)/2) - ((temp2Rect.right-temp2Rect.left)/2);
  1619.         MoveWindow(theWindow, tempRect.left, tempRect.top, TRUE);/* Move the window*/
  1620.         SetPort(theWindow);                         /* Prepare to write into our window */
  1621.         }
  1622.     }
  1623. }
  1624.  
  1625. /* ======================================================= */
  1626.  
  1627. /* Routine: GetDeepestColorScreenRect */
  1628. /* Purpose: Get the deepest color screen rect */
  1629.  
  1630. void GetDeepestColorScreenRect (Rect *DeepRect )
  1631. {
  1632. Rect        tempRect;                                /* Temporary rectangle */
  1633. GDHandle    theDevice;                                /* Graphic device */
  1634.  
  1635.  
  1636. *DeepRect = screenRect.bounds;                        /* Default to the main screen */
  1637. theDevice = NIL;                                    /* Default to no device */
  1638. if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  1639.     {
  1640.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1641.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1642.  
  1643.     if (theDevice != NIL)                            /* Make sure we got a device */
  1644.         *DeepRect = (*theDevice)->gdRect;            /* Get the device rect */
  1645.     }
  1646. }
  1647.  
  1648. /* ======================================================= */
  1649.  
  1650. void HiliteDefaultButton(DialogPtr theDialog,short theItem)
  1651. {
  1652. Rect            tempRect;
  1653. short            DType;                                /* Type of dialog item */
  1654. Handle            DItem;                                /* Handle to the dialog item */
  1655.  
  1656.  
  1657. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1658. PenSize(3, 3);                                        /* Change pen to draw thick default outline */
  1659. InsetRect(&tempRect, -4, -4);                        /* Draw outside the button by 1 pixel */
  1660. FrameRoundRect(&tempRect,16,16);                    /* Draw the outline */
  1661. PenSize(1, 1);                                         /* Restore the pen size to the default value */
  1662. }
  1663.  
  1664. /* ======================================================= */
  1665.  
  1666. void CheckKeysInDialog(DialogPtr theDialog,Boolean *valMyFilter,EventRecord *theEvent,short *itemHit)
  1667. {
  1668. short            chCode;                            /* Key entered */
  1669. char            MyCmdKey;                        /* The command key */
  1670. Boolean            CmdDown;                        /* Flag for command key used */
  1671. Rect            tempRect;                        /* Temporary rectangle */
  1672. short            DType;                            /* Type of dialog item */
  1673. Handle            DItem;                            /* Handle to the dialog item */
  1674. ControlHandle    CItem;                            /* Control handle */
  1675. long            LTemp;
  1676.  
  1677.  
  1678. if (theEvent->what == keyDown)
  1679.     {
  1680.     chCode =  (short)theEvent->message & charCodeMask;/* Get character */
  1681.     MyCmdKey = (char)chCode;                        /* Change to ASCII */
  1682.     CmdDown = ((theEvent->modifiers & cmdKey) != 0);/* Get command key state */
  1683.     if (CmdDown)                                    /* Do if command key was down */
  1684.         {
  1685.         if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
  1686.             {
  1687.             DlgCut(theDialog);
  1688.             *valMyFilter = TRUE;
  1689.             }
  1690.         else if ((MyCmdKey =='c') || (MyCmdKey == 'C')) 
  1691.             {
  1692.             DlgCopy(theDialog);
  1693.             *valMyFilter = TRUE;
  1694.             }
  1695.         else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
  1696.             {
  1697.             DlgPaste(theDialog);
  1698.             *valMyFilter = TRUE;
  1699.             }
  1700.         }
  1701.     else if ((chCode == 13) || (chCode == 3))        /* CR or Enter */
  1702.         {
  1703.         *valMyFilter = TRUE;                            /* Flag we got a hit */
  1704.         *itemHit = 1;                                /* Default for CR */
  1705.         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  1706.         if (DType == (ctrlItem + btnCtrl))            /* If a button then ... */
  1707.             {
  1708.             CItem = (ControlHandle)DItem;            /* Make it a controlhandle */
  1709.             HiliteControl(CItem, 10);                /* Hilite it */
  1710.             LTemp = TickCount() + 15;                /* Flash the button for 1/4 second */
  1711.             do
  1712.                 {}
  1713.             while (LTemp > TickCount());
  1714.             HiliteControl(CItem, 0);                /* UnHilite it */
  1715.             }
  1716.         }
  1717.     }
  1718. }
  1719.  
  1720. /* ======================================================= */
  1721.  
  1722. void SetupNormalControl(DialogPtr theDialog,short theItem,Boolean Enabled,short InitialValue)
  1723. {
  1724. Rect            tempRect;                            /* Temporary rectangle variable */
  1725. short            DType;                                /* Type of dialog item */
  1726. Handle            DItem;                                /* Handle to the dialog item */
  1727. ControlHandle    CItem;                                /* Control handle */
  1728.  
  1729.  
  1730. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1731. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1732.  
  1733. if (Enabled)                                        /* See if enable or disable the zone */
  1734.     HiliteControl (CItem,0);                        /* Enable the zone */
  1735. else
  1736.     HiliteControl (CItem,255);                        /* Dim the zone */
  1737.  
  1738. SetCtlValue(CItem,InitialValue);
  1739. }
  1740.  
  1741. /* ======================================================= */
  1742.  
  1743. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  1744.     ControlHandle *theCItem)
  1745. {
  1746. Rect            tempRect;                            /* Temporary rectangle variable */
  1747. short            DType;                                /* Type of dialog item */
  1748. Handle            DItem;                                /* Handle to the dialog item */
  1749. ControlHandle    CItem;                                /* Control handle */
  1750. Str255            sTemp;
  1751.  
  1752.  
  1753. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1754. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1755. SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1756.  
  1757. if (Enabled)                                        /* See if enable or disable the zone */
  1758.     HiliteControl (CItem,0);                        /* Enable the zone */
  1759. else
  1760.     HiliteControl (CItem,255);                        /* Dim the zone */
  1761.  
  1762. SetCtlValue(CItem,0);
  1763.  
  1764. if (MessageResID != 0)
  1765.     {
  1766.     GetIndString(sTemp,MessageResID,1);                /* Get the string */
  1767.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1768.     }
  1769. *theCItem = CItem;
  1770. }
  1771.  
  1772. /* ======================================================= */
  1773.  
  1774. void SetupHotSpot(DialogPtr theDialog,short theItem,Boolean MakeHotSpot,long LineWidth,
  1775.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1776. {
  1777. ControlHandle    CItem;                                /* Control handle */
  1778. long            LTemp;
  1779.  
  1780.  
  1781. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1782.  
  1783. if (MakeHotSpot)
  1784.     LTemp = 0x00FF0000;                                /* Tell the CDEF that it is a HotSpot */
  1785. else
  1786.     LTemp = 0x00000000;                                /* Tell the CDEF that it is a Rectangle */
  1787.  
  1788. if (MessageResID != 0)
  1789.     LTemp = LTemp + 0x01000000;
  1790.  
  1791. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  1792. LTemp = LTemp + (0x000000FF & ShadowWidth);            /* Set the shadow width */
  1793.  
  1794. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1795.  
  1796. ShowControl(CItem);                                    /* Show it to activate it */
  1797. }
  1798.  
  1799. /* ======================================================= */
  1800.  
  1801. void SetupPlugin(DialogPtr theDialog,short theItem,Boolean Enabled,long NormalID,long HilitedID,
  1802.     short MessageResID)
  1803. {
  1804. ControlHandle    CItem;                                /* Control handle */
  1805. long            LTemp;
  1806.  
  1807.  
  1808. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1809.  
  1810. LTemp = (HilitedID * 0x00010000) + NormalID;    
  1811. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1812.  
  1813. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1814.  
  1815. ShowControl(CItem);                                    /* Show it to activate it */
  1816. }
  1817.  
  1818. /* ======================================================= */
  1819.  
  1820. void SetupMinMaxValue(DialogPtr theDialog,short theItem,short min,short max,short value)
  1821. {
  1822. Rect            tempRect;                            /* Temporary rectangle variable */
  1823. short            DType;                                /* Type of dialog item */
  1824. Handle            DItem;                                /* Handle to the dialog item */
  1825. ControlHandle    CItem;                                /* Control handle */
  1826.  
  1827.  
  1828. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1829. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1830. SetCtlMin(CItem,min);                                /* The Min */
  1831. SetCtlMax(CItem,max);                                /* The Max */
  1832. SetCtlValue(CItem,value);                            /* The first selection */
  1833. }
  1834.  
  1835. /* ======================================================= */
  1836.  
  1837. void SetupPopupMenu(DialogPtr theDialog,short theItem,Boolean Enabled,short theMenuID,short value)
  1838. {
  1839. Rect            tempRect;                            /* Temporary rectangle variable */
  1840. short            DType;                                /* Type of dialog item */
  1841. Handle            DItem;                                /* Handle to the dialog item */
  1842. ControlHandle    CItem;                                /* Control handle */
  1843.  
  1844.  
  1845. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1846. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1847. SizeControl(CItem,tempRect.right - tempRect.left, tempRect.bottom - tempRect.top);/* Size it to the item size */
  1848. SetCtlValue(CItem,value);                            /* The first selection */
  1849. SetCtlMax(CItem,theMenuID);                            /* The max value is the menu ID */
  1850.  
  1851. if (Enabled)                                        /* See if enable or disable the zone */
  1852.     HiliteControl (CItem,0);                        /* Enable the zone */
  1853. else
  1854.     HiliteControl (CItem,255);                        /* Dim the zone */
  1855.  
  1856. SetNameForPopup(CItem);                                /* Set the popup title */
  1857. ShowControl(CItem);                                    /* Show it to activate it */
  1858. }
  1859.  
  1860. /* ======================================================= */
  1861.  
  1862. void SetupPalette(DialogPtr theDialog,short theItem,Boolean Enabled,long NumberRows,long NumberCols,
  1863.     long PalPictureID,long HiliteMethod)
  1864. {
  1865. ControlHandle    CItem;                                /* Control handle */
  1866.  
  1867.  
  1868. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1869.  
  1870. SetCtlMax(CItem,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  1871. SetCtlValue(CItem,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  1872. (*CItem)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  1873. ShowControl(CItem);                                    /* Show it to activate it */
  1874. }
  1875.  
  1876. /* ======================================================= */
  1877.  
  1878. void SetupIconSicn(DialogPtr theDialog,short theItem,Boolean Enabled,
  1879.     long NormalID,long HilitedID)
  1880. {
  1881. ControlHandle    CItem;                                /* Control handle */
  1882. long            LTemp;
  1883.  
  1884.  
  1885. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1886.  
  1887. LTemp = (NormalID * 0x00010000) + HilitedID;    
  1888. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1889.  
  1890. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1891.  
  1892. ShowControl(CItem);                                    /* Show it to activate it */
  1893. }
  1894.  
  1895. /* ======================================================= */
  1896.  
  1897. void ClearTheRadio(DialogPtr theDialog,short theItem,short *value)
  1898. {
  1899. Rect            tempRect;                            /* Temporary rectangle variable */
  1900. short            DType;                                /* Type of dialog item */
  1901. Handle            DItem;                                /* Handle to the dialog item */
  1902. ControlHandle    CItem;                                /* Control handle */
  1903.  
  1904.  
  1905. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get which item was pressed */
  1906. CItem = (ControlHandle)DItem;                        /* Change the pointer for getting to the control */
  1907. SetCtlValue(CItem,0);
  1908. *value = 0;                                            /* Set the current Radio value */
  1909. }
  1910.  
  1911. /* ======================================================= */
  1912.  
  1913. void DrawStaticTextBox(short ResID,Rect *theRect,short Justify,short theSize,
  1914.     short theFont,Style theStyle)
  1915. {
  1916. Str255        sTemp;
  1917.  
  1918.  
  1919. TextSize(theSize);                            /* Set text size */
  1920. TextFont(theFont);                            /* Set text font */
  1921. TextFace(theStyle);                            /* Set text style */
  1922. GetIndString(sTemp,ResID,1);                /* Get the string */
  1923. TextBox(&sTemp[1],sTemp[0],theRect,Justify);
  1924.  
  1925. TextFont(applFont);                            /* Back to the application font */
  1926. TextSize(12);                                /* Back to the application size */
  1927. TextFace(0);                                /* Set text style */
  1928. }
  1929.  
  1930. /* ======================================================= */
  1931.  
  1932. void DrawStaticLine(short ResID,short Left,short Top,short theSize,short theFont,Style theStyle)
  1933. {
  1934. Str255        sTemp;
  1935.  
  1936.  
  1937. TextSize(theSize);                            /* Set text size */
  1938. TextFont(theFont);                            /* Set text font */
  1939. TextFace(theStyle);                            /* Set text style */
  1940. GetIndString(sTemp,ResID,1);                /* Get the string */
  1941. MoveTo(Left,Top + theSize - 3);
  1942. DrawString(sTemp);
  1943.  
  1944. TextFont(applFont);                            /* Back to the application font */
  1945. TextSize(12);                                /* Back to the application size */
  1946. TextFace(0);                                /* Set text style */
  1947. }
  1948.  
  1949. /* ======================================================= */
  1950.  
  1951. void DrawTheTEArea(Rect *theTERect,TEHandle theTE,short theSize,short theFont,Style theStyle)
  1952. {
  1953.  
  1954.  
  1955. TextSize(theSize);                            /* Set text size */
  1956. TextFont(theFont);                            /* Set text font */
  1957. TextFace(theStyle);                            /* Set text style */
  1958. FrameRect(theTERect);                        /* Frame this TE area */
  1959. if (theTE != nil)
  1960.     TEUpdate(theTERect,theTE);                /* Update the TE area */
  1961.  
  1962. TextFont(applFont);                            /* Back to the application font */
  1963. TextSize(12);                                /* Back to the application size */
  1964. TextFace(0);                                /* Set text style */
  1965. }
  1966.  
  1967. /* ======================================================= */
  1968.  
  1969. ControlHandle MakeNormalControl(WindowPtr theWindow,short theResID,Boolean Enabled,short InitialValue)
  1970. {
  1971. ControlHandle    theCtrl;
  1972.  
  1973.  
  1974. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1975. SetCtlValue(theCtrl,InitialValue);                /* Set the value */
  1976. if (Enabled)
  1977.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1978. else
  1979.     HiliteControl(theCtrl,255);                    /* Disable the control */
  1980.  
  1981. return(theCtrl);
  1982. }
  1983.  
  1984. /* ======================================================= */
  1985.  
  1986. ControlHandle MakeHotSpot(WindowPtr theWindow,short theResID,Boolean MakeHotSpot,long LineWidth,
  1987.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1988. {
  1989. ControlHandle    theCtrl;
  1990. long            LTemp;
  1991. Str255            sTemp;
  1992.  
  1993.  
  1994. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1995. HideControl(theCtrl);                            /* Hide till we set all the parameters */
  1996.  
  1997. if (Enabled)
  1998.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1999. else
  2000.     HiliteControl(theCtrl,255);                    /* Disable the control */
  2001.  
  2002. if (MakeHotSpot)
  2003.     LTemp = 0x00FF0000;                            /* Tell the CDEF that it is a HotSpot */
  2004. else
  2005.     LTemp = 0x00000000;                            /* Tell the CDEF that it is a Rectangle */
  2006.  
  2007. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  2008. LTemp = LTemp + (0x000000FF & ShadowWidth);        /* Set the shadow width */
  2009.  
  2010. if (MessageResID != 0)
  2011.     {
  2012.     LTemp = LTemp + 0x01000000;
  2013.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  2014.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  2015.     }
  2016.  
  2017. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  2018.  
  2019. SetCtlValue(theCtrl,0);
  2020. ShowControl(theCtrl);                            /* Show it to activate it */
  2021.  
  2022. return(theCtrl);
  2023. }
  2024.  
  2025. /* ======================================================= */
  2026.  
  2027. ControlHandle MakeIconSicn(WindowPtr theWindow,short theResID,Boolean Enabled,
  2028.     long NormalID,long HilitedID)
  2029. {
  2030. ControlHandle    theCtrl;
  2031.  
  2032.  
  2033. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2034. if (Enabled)
  2035.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2036. else
  2037.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2038. (*theCtrl)->contrlData = 
  2039.         (Handle)((NormalID * 0x00010000) + HilitedID);    /* Set the icons to be used */
  2040.  
  2041. return(theCtrl);
  2042. }
  2043.  
  2044. /* ======================================================= */
  2045.  
  2046. ControlHandle MakePlugin(WindowPtr theWindow,short theResID,Boolean Enabled,
  2047.     long NormalID,long HilitedID,short MessageResID,short InitialValue)
  2048. {
  2049. ControlHandle    theCtrl;
  2050. long            LTemp;
  2051. Str255            sTemp;
  2052.  
  2053.  
  2054. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2055. HideControl(theCtrl);
  2056. if (Enabled)
  2057.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2058. else
  2059.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2060.  
  2061. LTemp = (HilitedID * 0x00010000) + NormalID;    
  2062. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  2063.  
  2064. SetCtlMax(theCtrl,12345);                        /* Set the flag to the CDEF */
  2065.  
  2066. if (MessageResID != 0)
  2067.     {
  2068.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  2069.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  2070.     }
  2071.  
  2072. SetCtlValue(theCtrl,InitialValue);
  2073. ShowControl(theCtrl);                            /* Show it to activate it */
  2074.  
  2075. return(theCtrl);
  2076. }
  2077.  
  2078. /* ======================================================= */
  2079.  
  2080. void MakeMinMaxValue(ControlHandle theControl,short min,short max,short value)
  2081. {
  2082.  
  2083. SetCtlMin(theControl,min);                                /* The Min */
  2084. SetCtlMax(theControl,max);                                /* The Max */
  2085. SetCtlValue(theControl,value);                            /* The first selection */
  2086. }
  2087.  
  2088. /* ======================================================= */
  2089.  
  2090. ControlHandle MakePopupMenu(WindowPtr theWindow,short theResID,Boolean Enabled,
  2091.     short theMenuID,short value)
  2092. {
  2093. ControlHandle    theCtrl;
  2094. long            LTemp;
  2095. Str255            sTemp;
  2096.  
  2097.  
  2098. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2099. HideControl(theCtrl);
  2100. if (Enabled)
  2101.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2102. else
  2103.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2104.  
  2105. SetCtlMax(theCtrl,theMenuID);                    /* Set the menu for the CDEF */
  2106.  
  2107. SetCtlValue(theCtrl,value);
  2108. SetNameForPopup(theCtrl);                        /* Set the popup title */
  2109. ShowControl(theCtrl);                            /* Show it to activate it */
  2110.  
  2111. return(theCtrl);
  2112. }
  2113.  
  2114. /* ======================================================= */
  2115.  
  2116. void UpdateTheList(RgnHandle theRgn,ListHandle theList,Rect *theRect,short theSize,
  2117.     short theFont,Style theStyle,Boolean InDialog)
  2118. {
  2119. Rect        tempRect;
  2120.  
  2121.  
  2122. TextSize(theSize);                            /* Set text size */
  2123. TextFont(theFont);                            /* Set text font */
  2124. TextFace(theStyle);                            /* Set text style */
  2125.  
  2126. LUpdate(theRgn,theList);                    /* Update this list */
  2127. tempRect = *theRect;                        /* Start with full size */
  2128. InsetRect(&tempRect, -1, -1);                /* Set for framing */
  2129. FrameRect(&tempRect);                        /* Frame it */
  2130.  
  2131. if (InDialog)
  2132.     TextFont(systemFont);                    /* Back to the system font */
  2133. else
  2134.     TextFont(applFont);                        /* Back to the application font */
  2135. TextSize(12);                                /* Back to the application size */
  2136. TextFace(0);                                /* Set text style */
  2137. }
  2138.  
  2139. /* ======================================================= */
  2140.  
  2141. void ClickInTheList(Point myPt,short modifiers,ListHandle theList,short theSize,
  2142.     short theFont,Style theStyle,Boolean InDialog)
  2143. {
  2144. Boolean        DoubleClick;
  2145.  
  2146.  
  2147. TextSize(theSize);                            /* Set text size */
  2148. TextFont(theFont);                            /* Set text font */
  2149. TextFace(theStyle);                            /* Set text style */
  2150.  
  2151. DoubleClick = LClick(myPt,modifiers,theList);
  2152.  
  2153. if (InDialog)
  2154.     TextFont(systemFont);                    /* Back to the system font */
  2155. else
  2156.     TextFont(applFont);                        /* Back to the application font */
  2157. TextSize(12);                                /* Back to the application size */
  2158. TextFace(0);                                /* Set text style */
  2159. }
  2160.  
  2161. /* ======================================================= */
  2162.  
  2163. ControlHandle MakePalette(WindowPtr theWindow,short theResID,Boolean Enabled,long NumberRows,
  2164.     long NumberCols,long PalPictureID,long HiliteMethod)
  2165. {
  2166. ControlHandle    theCtrl;
  2167.  
  2168.  
  2169. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2170. HideControl(theCtrl);
  2171. if (Enabled)
  2172.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2173. else
  2174.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2175.  
  2176. SetCtlMax(theCtrl,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  2177. SetCtlValue(theCtrl,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  2178. (*theCtrl)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  2179.  
  2180. ShowControl(theCtrl);                            /* Show it to activate it */
  2181.  
  2182. return(theCtrl);
  2183. }
  2184.  
  2185. /* ======================================================= */
  2186.  
  2187. void Activate_TE_Area(Boolean InDialog,Point myPt,TEHandle theTE,short textSize,short textFont,Style textStyle)
  2188. {
  2189.  
  2190.  
  2191. TextSize(textSize);                            /* Set text size */
  2192. TextFont(textFont);                            /* Set text font */
  2193. TextFace(textStyle);                        /* Set text style */
  2194. if (theInput != nil)                        /* See if there is already a Tarea */
  2195.     TEDeactivate(theInput);                    /* ...Yes, so turn it off */
  2196.  
  2197. theInput = theTE;
  2198. TEActivate(theInput);                        /* Turn it on */
  2199. TEClick(myPt,false,theInput);
  2200. if (InDialog)
  2201.     TextFont(systemFont);                    /* Back to the system font */
  2202. else
  2203.     TextFont(applFont);                        /* Back to the application font */
  2204. TextSize(12);
  2205. TextFace(0);
  2206. }
  2207.  
  2208. /* ======================================================= */
  2209. /* ======================================================= */
  2210. $$CloseFile
  2211.  
  2212.  
  2213.